package heap;

import java.util.*;

import Common.GlobalConst;

/**
 * The record schema of a table.
 * @author zhangyu
 *
 */


public class Schema implements GlobalConst{

	private Map <String ,FieldInfo> info = new HashMap<String ,FieldInfo> ();
	
	public Schema () {
		
	}
	
	public void addField (String fldname,int type,int length) {
		info.put(fldname, new FieldInfo(type, length));
	}
	
	public void setIntField () {
		
	}
	
	public void setFloField () {
		
	}
	/**
	 * 
	 * @param fldname
	 * @param length the number of chars
	 */
	public void setStrField (String fldname ,int length) {
		
	}
	
	/**
	 * Foreign key
	 * @author zhangyu
	 *
	 */
	public void addForeign (String fldname, Schema sch) {
		int type   = sch.type(fldname);
		int length = sch.length(fldname);
		addField(fldname, type, length);
		
	}
	
	public int type (String fldname) {
		return info.get(fldname).type;
	}
	
	public int length (String fldname) {
		return info.get(fldname).length;
	}
	
	public Collection<String> fields() {
		return info.keySet();
	}
	class FieldInfo {
		int type;
		int length;
		public FieldInfo (int type,int length) {
			this.type=type;
			this.length=length;
		}
	}
	
}
